import type { ResponseData } from '@/utils/types.d';
import { SUCCESS_CODE } from '@/utils/types.d';
import request from '@/utils/request';

export async function queryWechatRecharges(params: any, sort: any) {
  const res = await request('/api/wechat-user/v1.0.0/recharge/records', {
    method: 'GET',
    params: {
      data: params,
      sort,
    },
  });
  if (res?.code === SUCCESS_CODE)
    return { success: true, total: res.data.total, data: res.data.data };
  return { success: false, total: 0, data: [] };
}

export async function updateRechargeRecords(orderNo: string, newInfo: { remark: string }) {
  if (!orderNo || !newInfo || Object.keys(newInfo).length === 0)
    return { success: false, message: '更新失败，请填入需要更新的信息' };
  const res: ResponseData<null> = await request(
    `/api/wechat-user/v1.0.0/recharge/records/${orderNo}`,
    {
      method: 'PUT',
      data: newInfo,
    },
  );
  if (res?.code === SUCCESS_CODE) {
    return { success: true, data: res.data, message: '更新成功' };
  }
  return { success: false, data: res?.data, message: res?.message || '更新失败' };
}
